#include <stdio.h>

#define MAXSIZE 100
typedef int ElemType;

//顺序表的栈的定义
typedef struct 
{
	ElemType data[MAXSIZE]; //用来存储实际数据
	int top; //用来存储对应地址
	
}Stack;

//初始化
void initStack(Stack *s)
{
	s->top = -1; //把初始地址写成-1, 保证第一个元素下标从0开始
}

//判断栈是否为空
int isEmpty(Stack *s)
{
	if (s->top == -1) {
		printf("空的\n");
		return 1;
	}
	else return 0;
}

//压栈
int push(Stack *s, ElemType e)
{
	if (s->top >= MAXSIZE - 1) { //压栈之前先检查是否满栈
		printf("满了\n");
		return 0;
	}
	s->top++; //这里手动增加下标
	s->data[s->top] = e;
	return 1;
}

//弹栈
int pop(Stack *s, ElemType *e)
{
	if (s->top == -1) { //弹栈之前先检查是否空栈
		printf("空的\n");
		return 0;
	}
	*e = s->data[s->top];
	s->top--;
	return 1;
}

//获取栈顶元素
int getTop(Stack *s, ElemType *e)
{
	if (s->top == -1)
	{
		printf("空的\n");
		return 0;
	}
	*e = s->data[s->top];
	return 1;
}

int main(int argc, char const *argv[])
{
	
	Stack s;
	initStack(&s);
	push(&s, 10);
	push(&s, 20);
	push(&s, 30);
	ElemType e;
	pop(&s, &e);
	printf("%d\n", e);
	getTop(&s, &e);
	printf("%d\n", e);
	getTop(&s, &e);
	printf("%d\n", e);
	
	return 0;
}



